<html>
<head><meta charset="utf-8"><title>issue #78240 · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html">issue #78240</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="214234818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214234818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214234818">(Oct 22 2020 at 19:14)</a>:</h4>
<p>I don't think this issue is a bug, so I closed it, but I would appreciate someone else taking a look just to double-check! <a href="https://github.com/rust-lang/rust/issues/78240">#78240</a></p>



<a name="214235715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214235715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214235715">(Oct 22 2020 at 19:20)</a>:</h4>
<p>My explanation from the issue:</p>
<p>Here's my reasoning:</p>
<p>This code</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">panic</span><span class="o">!</span><span class="p">();</span><span class="w"> </span><span class="mi">0</span><span class="o">..</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>

<p>is equivalent to</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">range</span>: <span class="nc">RangeFrom</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">panic</span><span class="o">!</span><span class="p">();</span><span class="w"> </span><span class="mi">0</span><span class="o">..</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="k">for</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">range</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>

<p>. The type of <code>range</code> is <code>RangeFrom&lt;i32&gt;</code>; even if it <em>were</em> <code>!</code>, the type of the <code>for</code> expression should not depend on the type of the value it is iterating over.</p>
<p>And the same reasoning for <code>while { panic!(); false } {}</code>.</p>



<a name="214236000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214236000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214236000">(Oct 22 2020 at 19:23)</a>:</h4>
<p>I personally do think we want to allow for things like that but I am not completely sure about that. cc <span class="user-mention" data-user-id="121053">@varkor</span></p>



<a name="214236170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214236170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214236170">(Oct 22 2020 at 19:24)</a>:</h4>
<p>Your reasoning makes sense to me.  (It omits the <code>IntoIterator</code> step, but that's an identity for <code>Range</code> so it doesn't matter.)</p>



<a name="214236292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214236292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214236292">(Oct 22 2020 at 19:25)</a>:</h4>
<p>If there's a feature request here, it's that somebody wants <code>{ !; T }</code> to be <code>!</code> and not <code>T</code>, not anything to do with <code>for</code>.</p>



<a name="214236442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214236442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214236442">(Oct 22 2020 at 19:26)</a>:</h4>
<p>You don't need any loops to reproduce this, just a block</p>



<a name="214236546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214236546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214236546">(Oct 22 2020 at 19:27)</a>:</h4>
<p>But that's at least an inference-breaking change.  It might be a feasible one, though, since it only happens in cases with unreachable code.</p>
<p>Actually, thinking again, it might be weird for generics.  if you have <code>{ T; U }</code> it'd have to always be <code>U</code> even if <code>T</code> happens to be <code>!</code> sometimes.  So probably not a good idea to change the type in the concrete case.</p>



<a name="214237021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214237021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214237021">(Oct 22 2020 at 19:31)</a>:</h4>
<p>Yeah, I don't think this should be changed.</p>



<a name="214237056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214237056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214237056">(Oct 22 2020 at 19:31)</a>:</h4>
<p>If you have a panic in your code, that's a runtime thing. And rustc will warn you.</p>



<a name="214237103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214237103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214237103">(Oct 22 2020 at 19:31)</a>:</h4>
<p>It seems like that would be something for dependent types, which we don't have <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="214240211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240211">(Oct 22 2020 at 19:56)</a>:</h4>
<p>I do think something inconsistent is going on, because the following works, but doesn't if you uncomment the <code>()</code>.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="o">!</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">return</span><span class="w"> </span><span class="n">panic</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="c1">// ()</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="214240280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240280">(Oct 22 2020 at 19:56)</a>:</h4>
<p>Shouldn't any statement have type <code>()</code>, and therefore the two snippets should be equivalent?</p>



<a name="214240467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240467">(Oct 22 2020 at 19:57)</a>:</h4>
<p><del><code>return</code> isn't type-dependent, so it might be because of the control flow instead of the type.</del></p>



<a name="214240587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240587">(Oct 22 2020 at 19:58)</a>:</h4>
<p><del><code>'a: { break panic!(); () }</code> being different from <code>{ panic!(); () }</code> doesn't seem unreasonable.</del></p>



<a name="214240654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240654">(Oct 22 2020 at 19:59)</a>:</h4>
<p><del>Err, ignore that.</del></p>
<p>I guess something special-cased a final <code>return foo;</code> so that the semicolon was allowed</p>



<a name="214240819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240819">(Oct 22 2020 at 20:00)</a>:</h4>
<p>afaik we have some special casing re <code>stmt.diverges</code> or something</p>



<a name="214240856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214240856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214240856">(Oct 22 2020 at 20:00)</a>:</h4>
<p>but that's something I never really looked into too much</p>



<a name="214241937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214241937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214241937">(Oct 22 2020 at 20:08)</a>:</h4>
<p>I personally think it's nice to be clever about diverging code like this, but it tends only to occur in weird scenarios anyway, so it's not a big deal either way.</p>



<a name="214242175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/issue%20%2378240/near/214242175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/issue.20.2378240.html#214242175">(Oct 22 2020 at 20:10)</a>:</h4>
<p>I think there may have been a time when <code>!</code> anywhere was treated as diverging, but I think it's less enthusiastic about that now.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>